<template>

  <div class="bg-container">
    <div class="login-container">
      <el-card class="login-card">
        <div class="title-container">
          <h3 class="title" >阳陂湖综合管理平台</h3>
        </div>
        <el-form
          ref="loginForm"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
          auto-complete="on"
          label-position="left"
        >


          <el-form-item prop="username" class="login-input">

            <el-input
              ref="username"
              v-model="loginForm.username"
              placeholder="请输入用户名"
              name="username"
              type="text"
              tabindex="1"
              auto-complete="on"
            >
              <span slot="prefix" class="svg-container">
                <i class="iconfont icon-zhanghaoxinxi"></i>
              </span>
            </el-input>
          </el-form-item>

          <el-form-item prop="password" class="login-input">

            <el-input
              ref="password"
              v-model="loginForm.password"
              type="password"
              placeholder="请输入密码"
              name="password"
              tabindex="2"
              auto-complete="on"
              @keyup.enter.native="handleLogin"
            >
              <span slot="prefix" class="svg-container">
                <i class="iconfont icon-zhanghaoanquan"></i>
              </span>
            </el-input>
          </el-form-item>
          <el-button
            :loading="loading"
            type="primary"
            style="width:100%;margin-bottom:30px;background-color: #89949e;"
            @click.native.prevent="handleLogin" class="login-btn"
          >登录</el-button>
        </el-form>
        <h5 class="title" >©富春山居 yangpihu.net</h5>
      </el-card>
    </div>
    <fade-transition>
      <div class="bg-box" v-show="isShow">
        <div class="logo" >
          <el-image src="http://qiniu.yangpihu.net/top.png"></el-image>
        </div>
        <div class="logo" >
          <circle5 class="top-icon"></circle5>
        </div>
        <div class="top-title">
          <b>阳陂湖综合管理平台</b>
        </div>
      </div>
    </fade-transition>
  </div>
</template>

<script>
import { validUsername } from "@/utils/validate.ts";
import { FadeTransition } from 'vue2-transitions';
import { Circle5 } from 'vue-loading-spinner';


export default {
  name: "Login",
  components: {
    FadeTransition,
    Circle5,
  },
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!validUsername(value)) {
        callback(new Error("Please enter the correct user name"));
      } else {
        callback();
      }
    };
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error("The password can not be less than 6 digits"));
      } else {
        callback();
      }
    };
    return {
      loginForm: {
        username: "admin",
        password: "admin"
      },
      loginRules: {
        username: [{ required: true, trigger: "blur" }],
        password: [{ required: true, trigger: "blur" }]
      },
      loading: false,
      passwordType: "password",
      redirect: undefined,


      isShow: true,
      timeOutID: null,
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          this.$store
            .dispatch("login", this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || "/" });
              this.loading = false;
            })
            .catch(() => {
              this.loading = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  },
  mounted() {
    this.timeOutID = setTimeout(() => {
      this.isShow = false
      clearTimeout(this.timeOutID)
    }, 1800)
  }
};
</script>

<style lang="scss">
body {
  margin: 0px;
  padding: 0px;
}
.bg-box{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0px;
  bottom: 0px;
  background: #000000;
  z-index: 999!important;
  overflow:hidden; word-break:break-all;
  //display: none;
}
.logo{
  margin-right: -75px;
  width: 150px;
  position: absolute;
  right:65%;
  top:45%;
}
.top-title{
  color:#fff;
  font-size: 44px;
  position: relative;
  right:-45%;
  top:50%;
}
.icon-zhanghaoxinxi{
  color:#409eff;
}
.icon-zhanghaoanquan{
  color:#409eff;
}
.login-input{
  margin-top: 2rem;
}
.login-btn{
  margin-top: 1rem;
}
.spinner[data-v-51d0b8a8]:after{
  background: #eef5db73!important;
}
.spinner[data-v-51d0b8a8]:before{
  background: #f1c0548a !important;
}
.top-icon{
  width: 165px!important;
  height: 165px!important;
}
.bg-container {
  width: 100vw;
  height: 100vh;
  background: url("/login_images/login_bg.jpeg") no-repeat center;
  background-size: cover;
}
.login-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background: url("/login_images/poster-drop-animate1.png") center;
  background-size: cover;
  animation: posterDrop2 8000s linear infinite;
}

.login-card {
  width: 340px;
  background-color: #fbfdff;
  background-image: linear-gradient(#ffffff, #cccccc);
  -moz-box-shadow:-3px -5px 8px 3px #CCC4C4;
  -webkit-box-shadow:-3px -5px 8px 3px #CCC4C4;
  box-shadow:4px 5px 6px 4px rgb(0 0 0 / 41%)!important;
  background: rgba(91, 127, 165, 0.3);
  border-radius: 15px;
  height: 380px;
  margin-right: 10rem;
}

@keyframes posterDrop2 {
  from { background-position: 0 0; }
  to { background-position: 30000% 0; }
}
.title{
  text-align: center;
  padding-bottom: 20px;
  color:#fff;
}

</style>
